package com.xiaojian.pick.controller;

import com.xiaojian.pick.entity.ApplyBond;
import com.xiaojian.pick.page.AjaxResult;
import com.xiaojian.pick.service.ApplyBondService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author whycode
 * @title: ApplyBondController
 * @projectName campus-secondary-market-app---sys
 * @description: TODO
 * @date 2022/2/2015:04
 */

@RestController
@RequestMapping("/apply")
public class ApplyBondController {

    @Resource
    private ApplyBondService applyBondService;

    @PostMapping("")
    public AjaxResult add(@RequestBody ApplyBond applyBond){
        boolean save = applyBondService.save(applyBond);
        return new AjaxResult(save);
    }

    @GetMapping("/{id}")
    public AjaxResult getById(@PathVariable("id") Long id){
        ApplyBond applyBond = applyBondService.getById(id);
        return new AjaxResult(true).setData(applyBond);
    }

    @GetMapping("/list")
    public AjaxResult getList( ApplyBond applyBond){
        Map<String, Object> objectMap = applyBondService.list(applyBond);
        return new AjaxResult(true).setData(objectMap);
    }


    @PutMapping("/status/{id}")
    @ResponseBody
    public AjaxResult updateStatus(@PathVariable("id") Long id,
                                   Short status,
                                   Integer commId,
                                   String refuse){
        boolean res = applyBondService.updateStatus(id, status, refuse);
        Map<String, Object> list = applyBondService.list(new ApplyBond().setCommodity(commId));
        return new AjaxResult(res).setData(list.get("list"));
    }
}
